FROM php:8.2-fpm

# 替换 sources.list 文件为阿里云的 bookworm 源
RUN rm -rf /etc/apt/sources.list.d/* && \
    echo "deb http://mirrors.aliyun.com/debian bookworm main contrib non-free" > /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list



# 更新 apt 并安装所需的软件包
RUN apt-get update && \
    apt-get install -y \
    libyaml-dev \
    libzip-dev \
    zip \
    libpq-dev \
    libxml2-dev \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    git && \  
    rm -rf /var/lib/apt/lists/*

# 安装 php-bcmath 扩展
RUN docker-php-ext-install bcmath

# 安装 Filter 扩展
RUN docker-php-ext-install filter

# 安装 PHP zip 扩展
RUN docker-php-ext-install zip

# 安装 GD 扩展
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \
    docker-php-ext-install gd

# 安装 MySQL 扩展
RUN docker-php-ext-install mysqli pdo pdo_mysql

# 安装 Redis 扩展
RUN pecl install -o -f redis-5.3.4 && docker-php-ext-enable redis

# 安装 sockets 扩展
RUN docker-php-ext-install sockets

# Set upload_max_filesize
RUN echo "upload_max_filesize = 512M" > /usr/local/etc/php/conf.d/uploads.ini && \
    echo "post_max_size = 512M" >> /usr/local/etc/php/conf.d/uploads.ini

# 安装 Composer
RUN curl -sS https://getcomposer.org/installer | php && \
    mv composer.phar /usr/local/bin/composer

# 切换用户为 root
USER root

# 直接启动脚本
CMD ["/usr/local/bin/start.sh"]
# CMD ["php-fpm"]
